package com.itany.ums.entity;

import com.itany.ums.constant.RoleEnum;
import com.itany.ums.constant.StateEnum;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class User implements Cloneable {
	private Long id;
	private String username;
	private String password;
	private String phone;
	private String email;

	// 角色(role, 1: 管理员, 2: 普通用户)
	private Integer role;

	// 状态(state, 1: 启用, 0: 禁用)
	private Integer state;

	public User(String username, String password, String phone, String email) {
		this.username = username;
		this.password = password;
		this.phone = phone;
		this.email = email;
	}

	public String getRoleName() {
		if (this.role.equals(RoleEnum.ADMIN.getRoleCode())) {
			return RoleEnum.ADMIN.getRoleName();
		}
		if (this.role.equals(RoleEnum.NORMAL.getRoleCode())) {
			return RoleEnum.NORMAL.getRoleName();
		}
		return "未知";
	}

	public String getStateName() {
		if (this.state.equals(StateEnum.ENABLE.getStateCode())) {
			return StateEnum.ENABLE.getStateName();
		}
		if (this.state.equals(StateEnum.DISABLE.getStateCode())) {
			return StateEnum.DISABLE.getStateName();
		}
		return "未知";
	}

	@Override
	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			return null;
		}
	}

}
